package com.example.administrator.yuejian35.Club.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.administrator.yuejian35.Club.activity.ClubInfoActivity;
import com.example.administrator.yuejian35.Club.bean.Course;
import com.example.administrator.yuejian35.Club.fragment.viewholder.CourseItemViewHolder1;
import com.example.administrator.yuejian35.R;
import com.example.administrator.yuejian35.Recommend.activity.CourseinfoActivity;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import static com.example.administrator.yuejian35.Config.Img_URL;

/**
 * Created by HP on 2017/9/26.
 */

public class CourseListAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<Course> courseList=new ArrayList<>();
   /* private List<Integer> heightList;*/


    public CourseListAdapter(Context c, List<Course> courseList){
        this.context = c;
        this.courseList.addAll(courseList);
      /*  heightList = new ArrayList<>();
        for (int i = 0; i < courseList.size(); i++) {
            int height = new Random().nextInt(120) + 300;//[300,420)的随机数
            heightList.add(height);
        }*/

    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //1)  将item.xml 生成 itemView  -  View
        //2)  生成MyViewHolderd对象
        View itemView = LayoutInflater.from(context).inflate(R.layout.item_course1,parent,false);
        CourseItemViewHolder1 holder = new CourseItemViewHolder1(itemView);
        return holder;
    }



    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        //用于绑定数据
        //转换类型m
        CourseItemViewHolder1 courseItemViewHolder= (CourseItemViewHolder1) holder;

      /*  //由于需要实现瀑布流的效果,所以就需要动态的改变控件的高度了
        ViewGroup.LayoutParams params = courseItemViewHolder.relativelayout.getLayoutParams();
        params.height=heightList.get(position);
        courseItemViewHolder.relativelayout.setLayoutParams(params);*/

        /*final Course course1 = (Course) courseList.get(position);*/
        courseItemViewHolder.course_name.setText(courseList.get(position).getCoursename());
        courseItemViewHolder.money.setText("售价:"+courseList.get(position).getPrice()+"元");
        courseItemViewHolder.course_intro.setText("简介："+courseList.get(position).getCourseintro());
        courseItemViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,CourseinfoActivity.class);
                intent.putExtra("courseid",courseList.get(position).getCourseid());
                context.startActivity(intent);
            }
        });
        Picasso.with(context)
                .load(Img_URL+courseList.get(position).getCoursepic())
                .into(courseItemViewHolder.course_pic);


    }



    @Override
    public int getItemCount() {
        return courseList.size();
    }
}

